#include <stdint.h>

#include "ws2811.h"

#include "pwm.h"


// Mapping of Pin to alternate function for PWM channel 0
const pwm_pin_table_t pwm_pin_chan0[] = {
    pwm_pin_table_t(12, 0),
    pwm_pin_table_t(18, 5),
    pwm_pin_table_t(40, 0)
};

// Mapping of Pin to alternate function for PWM channel 1
const pwm_pin_table_t pwm_pin_chan1[] = {
    pwm_pin_table_t(13, 0),
    pwm_pin_table_t(19, 5),
    pwm_pin_table_t(41, 0),
    pwm_pin_table_t(45, 0)
};

const pwm_pin_tables_t pwm_pin_tables[RPI_PWM_CHANNELS] = {
    {pwm_pin_chan0, sizeof(pwm_pin_chan0) / sizeof(pwm_pin_chan0[0])},
    {pwm_pin_chan1, sizeof(pwm_pin_chan1) / sizeof(pwm_pin_chan1[0])}
};

int pwm_pin_alt(int chan, int pinnum) {
    const pwm_pin_tables_t& pintable = pwm_pin_tables[chan];

    for (size_t i = 0; i < pintable.count; ++i) {
        if (pintable.pins[i].pinnum == pinnum) {
            return pintable.pins[i].altnum;
        }
    }
    return -1;
}
